<%-- 
    Document   : loginAction
    Created on : 2021-12-14, 21:57:17
    Author     : Mayiyaheila
--%>

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="Vo.User"%>
<%@page import="Dao.UserDao"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <%
        request.setCharacterEncoding("utf-8");
        String uid = request.getParameter("Uid");
        String password = request.getParameter("password");

        String imageText = request.getParameter("image");
        String text = (String) request.getSession().getAttribute("text");

        if (!text.equalsIgnoreCase(imageText)) {
            request.setAttribute("imageMess", "验证码输入错误!");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }

        UserDao udao = new UserDao();
        User user = null;
        try {
            user = udao.getUserByAccount(uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (user == null || !user.getPassword().equals(password)) {
    %>
    <div style="text-align:center">
        登录失败,用户名或密码输入错误<a href="login.jsp">返回登录页面</a>
    </div>

    <%
        } else {
                session.setAttribute("user", user);
                response.sendRedirect("home.jsp");
            }
    %>
    </body>
</html>
